﻿Imports Sistema_InformacionNaviera.BC
Imports Sistema_InformacionNaviera.BE
Imports Sistema_InformacionNavier.UTIL


Public Class Consultar_BillOfLading

    'Inherits System.Web.UI.Page
    Inherits PaginaBase

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            txtNave.Text = "" : txtPto.Text = "" : txtNroBl.Text = "" : lblKvje.Text = 0
        End If
        If My.Request.Params("__EVENTTARGET") = "MiFuncionPaquetes" Then
            CargarDatosViajePopUp()
        End If


        CargarGridConsulta()

    End Sub

    Public Sub CargarDatosViajePopUp()

        If Session("BPCodViaje") = Nothing Then
            txtNave.Text = String.Empty
            txtDescripcionNave.Text = String.Empty
        Else
            txtNave.Text = Session("BPCodViaje")
            txtDescripcionNave.Text = Session("BPDesViaje")
        End If
    End Sub

    Protected Sub btnGrabar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnConsultar.Click
        CargarGridConsulta()
    End Sub

    Public Sub CargarGridConsulta()
        Dim objBlImpoBE As New BillOfLadingImpoBE
        Dim lstBlImpoBE As New List(Of BillOfLadingImpoBE)
        Dim objUtil As New Funciones
        Dim objBlImpoBC As New BillOfLadingImpoBC
        objBlImpoBE.KVJE = Val(txtNave.Text)
        objBlImpoBE.Ptoo = IIf(txtPto.Text.Trim = "", "", txtPto.Text.Trim)
        objBlImpoBE.Nume = IIf(txtNroBl.Text.Trim = "", "", txtNroBl.Text.Trim)

        lstBlImpoBE = objBlImpoBC.ListarBlImpo(objBlImpoBE)
        dgBlImportacion.DataSource = lstBlImpoBE
        dgBlImportacion.DataBind()
    End Sub


    Protected Sub btnNuevo_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnNuevo.Click

        ' elelgir una nave/ viaje
        '----------------------------------------------------------------------------
        If txtNave.Text.Trim = String.Empty Then
            Alerta("Seleccione una nave/viaje.", False, String.Empty)
            Exit Sub
        Else
            Session("CodNaveViajeBLImpo") = txtNave.Text.Trim
            Session("DesNaveViajeBLImpo") = txtDescripcionNave.Text.Trim
        End If

        '----------------------------------------------------------------------------
        Response.Redirect("BillOfLading.aspx", True)
        Session("tbTempFleteTipoTransaccion") = 0 ' si es nuevo
        '----------------------------------------------------------------------------
    End Sub

    Protected Sub btnLimpiar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnLimpiar.Click
        txtNave.Text = String.Empty
        txtDescripcionNave.Text = String.Empty
        txtNroBl.Text = String.Empty
        txtPto.Text = String.Empty

    End Sub

    Private Sub dgBlImportacion_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles dgBlImportacion.RowCommand
        If Val(lblKvje.Text) > 0 Then
            Dim intCodigo As Integer = Convert.ToInt32(e.CommandArgument)
            Dim iViaje As Integer = Val(lblKvje.Text)
            Dim sMensaje As String = String.Empty
            Dim bExito As Boolean

            Select Case e.CommandName  '.ToLower
                Case "Editar"

                    Session("TipoEvento") = 1 ' modificar
                    Session("CodigBL") = intCodigo
                    Session("CodigVje") = iViaje
                    Response.Redirect("BLImportacion.aspx", True)

                Case "Eliminar"

                    Dim objBlImpoBE As New BillOfLadingImpoBE
                    objBlImpoBE.KVJE = iViaje
                    objBlImpoBE.KBLM = intCodigo

                    Dim objPaqueteBC As New BillOfLadingImpoBC

                    objPaqueteBC.EliminarBlImpo(objBlImpoBE, bExito, sMensaje)
                    If bExito Then
                        Alerta("El registro fue eliminado con éxito.", False, String.Empty)
                        CargarGridConsulta()
                    End If

            End Select
        End If
    End Sub

    'Protected Sub ASPxButtonEdit1_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ASPxButtonEdit1.TextChanged
    '    Response.Redirect("../page/PopUp/BuscarPuerto.aspx", True)
    'End Sub

    Protected Sub dgBlImportacion_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles dgBlImportacion.SelectedIndexChanged

    End Sub
End Class